//
//  DevicePrepaireReportViewController.m
//  DevicePrepaireReport
//
//  Created by MacBook Pro on 16/7/20.
//  Copyright © 2016年 guotongbo. All rights reserved.
//
//屏幕的宽
#define SCREENW self.view.bounds.size.width
//屏幕的高
#define SCREENH self.view.bounds.size.height
#define Margin 5
#define LineLen 1;
// RGB颜色
#define TBColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]

#import "DevicePrepaireReportViewController.h"
#import "BorderButton.h"
#import "NrowLabelMessage.h"
#import "NrowLabelViewCell.h"
#import "RSCheckBox.h"
#import "RSCheckGroup.h"
#import "MyButton.h"
#import "TouchView.h"
#import "UPDbManager.h"
#import "SignsViewController.h"
#import "PullMenu.h"
#import "ServerProvider.h"
#import "NrowLabelMessage.h"
#import "ServeRecordCell.h"
#import "ServeRecordArr.h"
#import "PartRecordViewCell.h"
#import "PartRecordMessage.h"
#import "BorderTextField.h"
@interface DevicePrepaireReportViewController ()<UITableViewDelegate,UITableViewDataSource,UIPickerViewDelegate,UIPickerViewDataSource>

{
    /**邮箱*/
    UIButton *emailBtn;
    /**邮箱线*/
    UIView *emailLine;
    /**邮箱textField*/
    UITextField *emailTextF;
    /**保存*/
    UIButton *saveBtn;
    /**提交 */
    UIButton *sumbitBtn;
    /**预览*/
    UIButton *previewBtn;
    /**数据*/
    NSArray *info;
    /**区头*/
    NSMutableDictionary *header;
    /**下拉状态*/
    BOOL status;
    /**区头的View*/
    UIView *headerV;
    /**设备类型字符串*/
    NSString *deviceStr;
    /**设备类型数据数组*/
    NSArray *deviceArr;
    /**保修类型数据数组*/
    NSArray *maintainArr;
    /**保修类型字符串*/
    NSString *maintainStr;
    /**服务完成状态字符串*/
    NSString *serveFinishStr;
    /**服务分类字符串*/
    NSMutableString *serveStr;
    /**设备类型Btn*/
    UIButton *deviceBtn;
    /**单选按钮类型View*/
    UIPickerView *singleView;
    /**时间按钮类型Picker*/
    UIDatePicker *dateP;
    /**保修类型Btn*/
    UIButton *maintainBtn;
    /**服务分类Btn*/
    UIButton *serveBtn;
    /**复选框*/
    UIView *doubleView;
    /**服务分类字符串*/
    NSString *str;
    /**是否增加*/
    BOOL isAdd;
    /**签名图片*/
    UIImageView *signImgView;
    /**触屏*/
    TouchView *TouchV;
    /**邮件地址Label*/
    UILabel *emailLabel;
    RSCheckGroup *checkGroup;
    /**区脚View*/
    UIView *footView;
    /**pickView*/
     UIView *pickerView;
    /**开始时间datePickerStr*/
    NSString *beginTimeDatePStr;
    /**结束时间datePickerStr*/
    NSString *endTimeDatePStr;
    /**已完成*/
    BOOL isFinish;
    /**未完成*/
    BOOL isUnFinish;
    /**满意度数据数组*/
    NSArray *satisfiedArr;
    /**满意度Btn*/
    UIButton *satisfiedBtn;
    /**满意度字符串*/
    NSString *satisfiedStr;
    /**邮箱数组*/
    NSMutableArray *emailArr;
    /**邮箱menuStr*/
    NSString *menuStr;
    /**时间数组*/
    NSMutableArray *Timearr;
    NSMutableDictionary *dic;
    NSString *trafficStr;
    NSString *date;
}
@end
@implementation DevicePrepaireReportViewController
/**tableView*/
@synthesize tableV;
/**服务行为报告模型*/
@synthesize nLM;
/**服务记录数组的模型*/
@synthesize serveRecord;
/**服务记录的模型数组*/
@synthesize serveRecordArr;
/**坏见序列号的模型数组*/
@synthesize badPartModArr;
- (void)viewDidLoad {
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"设备维修单";
    [super viewDidLoad];
    //取数据
    [self GetData];
    //搭建界面
    [self setUpInterface];
    //改变导航栏的颜色、字体
    [self initNav];
}
-(void)initNav{
    
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:93/255.0 green:199/255.0 blue:255/255.0 alpha:1.0]];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
   }
//取数据
-(void)GetData{
    NSString *path = [[NSBundle mainBundle]pathForResource:@"DevicePrepair" ofType:@"plist"];
    info = [NSArray arrayWithContentsOfFile:path];
    
    header = [NSMutableDictionary dictionary];
    nLM = [[NrowLabelMessage alloc]init];
    serveRecord = [[ServeRecordArr alloc]init];
    serveRecordArr = [NSMutableArray array];
    badPartModArr = [NSMutableArray array];
    Timearr = [NSMutableArray array];
    dic =[NSMutableDictionary dictionary];
        nLM.serviceId = self.serviceId;
        nLM.customerName = self.strHospitalName;
        nLM.department = self.strDepartment;
        nLM.operatorStr = self.strLinkMan;
        nLM.eqType = self.eqTypeId;
        nLM.eqSeq = self.strEqseq;
}
//搭建界面
-(void)setUpInterface{
    
    //top和下面的按钮
    [self setUpBaseInfo];
    tableV = [[UITableView alloc]initWithFrame:CGRectMake(0,emailLine.frame.origin.y + 2 , SCREENW, saveBtn.frame.origin.y - emailLine.frame.origin.y + 1)style:UITableViewStyleGrouped];
    tableV.separatorStyle = NO;
    tableV.delegate = self;
    tableV.dataSource = self;

    //tableV.style = UITableViewStyleGrouped;
    [self.view addSubview:tableV];
    // 设置额外滚动区域
    tableV.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
}
//基本信息
-(void)setUpBaseInfo{
    //邮箱
    emailBtn = [[UIButton alloc]init];
    [emailBtn setImage:[UIImage imageNamed:@"c_7"] forState:UIControlStateNormal];
    CGFloat emailBtnX = SCREENW - 45;
    CGFloat emailBtnY = 69;
    CGFloat emailBtnW = 32;
    CGFloat emailBtnH = 32;
    emailBtn.frame = CGRectMake(emailBtnX, emailBtnY, emailBtnW, emailBtnH);
    [emailBtn addTarget:self action:@selector(sendEmail) forControlEvents:UIControlEventTouchUpInside ];
    
    [self.view addSubview:emailBtn];
    
    //邮箱线
    emailLine = [[UIView alloc]init];
    emailLine.backgroundColor = TBColor(212, 212, 212, 1);
    CGFloat emailLineX = 0;
    CGFloat emailLineY = emailBtnY + emailBtnH + Margin;
    CGFloat emailLineW = SCREENW;
    CGFloat emailLineH = LineLen;
    emailLine.frame = CGRectMake(emailLineX, emailLineY, emailLineW, emailLineH);
    [self.view addSubview:emailLine];
    
    //保存
    saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn.backgroundColor = TBColor(237, 237, 237, 1);
    saveBtn.layer.borderColor = [UIColor grayColor].CGColor;
    saveBtn.layer.borderWidth = 1;
    CGFloat saveBtnX = 0;
    CGFloat saveBtnY = SCREENH - 40;
    CGFloat saveBtnW = SCREENW/3;
    CGFloat saveBtnH = 40;
    saveBtn.frame = CGRectMake(saveBtnX, saveBtnY, saveBtnW, saveBtnH);
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [saveBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [self.view addSubview:saveBtn];
    
    //提交
    sumbitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sumbitBtn.backgroundColor = TBColor(237, 237, 237, 1);
    CGFloat sumbitBtnX = saveBtnW - 1 ;
    CGFloat sumbitBtnY = saveBtnY;
    CGFloat sumbitBtnW = saveBtnW ;
    CGFloat sumbitBtnH = saveBtnH;
    sumbitBtn.frame = CGRectMake(sumbitBtnX, sumbitBtnY, sumbitBtnW, sumbitBtnH);
    [sumbitBtn setTitle:@"提交" forState:UIControlStateNormal];
    [sumbitBtn addTarget:self action:@selector(submitClick) forControlEvents:UIControlEventTouchUpInside];
    [sumbitBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [sumbitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    sumbitBtn.layer.borderColor = [UIColor grayColor].CGColor;
    sumbitBtn.layer.borderWidth = 1;
    [self.view addSubview:sumbitBtn];
    
    //预览
    previewBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    previewBtn.backgroundColor = TBColor(237, 237, 237, 1);
    CGFloat previewBtnX = sumbitBtnW * 2 - 2 ;
    CGFloat previewBtnY = sumbitBtnY;
    CGFloat previewBtnW = sumbitBtnW + 2 ;
    CGFloat previewBtnH = sumbitBtnH;
    previewBtn.frame = CGRectMake(previewBtnX, previewBtnY, previewBtnW, previewBtnH);
    [previewBtn setTitle:@"预览" forState:UIControlStateNormal];
    [previewBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [previewBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    previewBtn.layer.borderColor = [UIColor grayColor].CGColor;
    previewBtn.layer.borderWidth = 1;
    [self.view addSubview:previewBtn];
    emailArr = [NSMutableArray array];

}
//提交点击事件
-(void)submitClick{
    NrowLabelMessage *submit = [[NrowLabelMessage alloc]init];
    submit.serviceId = self.serviceId;
    submit.department = nLM.department;
    submit.customerName = nLM.customerName;
    submit.contactAddress = nLM.contactAddress;
    submit.eqSeq = nLM.eqSeq;
    submit.eqTypeId = nLM.eqTypeId;
    submit.eqType = nLM.eqType;
    submit.eqStyle = nLM.eqStyle;
    submit.departTel = nLM.departTel;
    submit.operatorStr = nLM.operatorStr;
    submit.departLeader = nLM.departLeader;
    submit.serviceType = nLM.serviceType;
    submit.otherServiceName = nLM.otherServiceName;
    submit.otherType = nLM.otherType;
    submit.otherTypeName = nLM.otherTypeName;
    submit.failurePhenomena = nLM.failurePhenomena;
    submit.content = nLM.content;
    [Timearr addObject:dic];
    submit.workDates = Timearr;
    
    [ServerProvider serveActionReportSubmit:submit result:^(ServerReturnInfo *retInfo) {
//        if (retInfo.bSuccess == YES) {
//            NSLog(@"%@",retInfo.data);
//        }else{
//            NSLog(@"%@",retInfo.strErrorMsg);
//        }
    }];
}
//点击邮件事件
-(void)sendEmail{
    NSLog(@"发送了");
    NSLog(@"Email%@",emailArr);
    if (emailArr.count == 0) {
        UIView *emailView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
        emailView.tag = 7;
        emailView.backgroundColor = [UIColor clearColor];
        [self.view addSubview:emailView];
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(18, SCREENW / 3, SCREENW - 36, 150)];
        view.layer.backgroundColor = TBColor(94, 204, 250, 1).CGColor;
        view.layer.borderWidth = 1;
        view.backgroundColor = [UIColor whiteColor];
        [emailView addSubview:view];
        
        emailLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 5, SCREENW - 105, 30)];
        emailLabel.text = @"请输入邮箱地址:";
        [view addSubview:emailLabel];
        
        emailTextF = [[UITextField alloc]initWithFrame:CGRectMake(25, 40, SCREENW * 4/5, 30)];
        emailTextF.backgroundColor = TBColor(212, 212, 212, 1);
        [view addSubview:emailTextF];
        
        UILabel *textMargin = [[UILabel alloc]initWithFrame:CGRectMake(20, 40, 5, 30)];
        textMargin.backgroundColor = TBColor(212, 212, 212, 1);
        [view addSubview:textMargin];
        
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(SCREENW * 4/5 - 80, 90, 80, 30)];
        [btn setTitle:@"发送" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        btn.backgroundColor = TBColor(102, 85, 191, 1);
        [btn addTarget:self action:@selector(sendE) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:btn];
        
        UIButton *cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(40, 90, 80, 30)];
        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [cancelBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        cancelBtn.backgroundColor = TBColor(102, 85, 191, 1);
        [cancelBtn addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:cancelBtn];
    }else{
        NSInteger emailPullMenuViewW = SCREENW - 36;
        UIView *emailPullMenuView = [[UIView alloc]initWithFrame:CGRectMake(18, SCREENW / 3, emailPullMenuViewW, 180)];
        emailPullMenuView.backgroundColor = [UIColor whiteColor];
        emailPullMenuView.layer.borderColor = [UIColor blackColor].CGColor;
        emailPullMenuView.layer.borderWidth = 1;
        emailPullMenuView.tag = 23;
        [self.view addSubview:emailPullMenuView];
        
        NSInteger menuW = SCREENW - 105;
        PullMenu *menu = [[PullMenu alloc]initWithFrame:CGRectMake(20, 25, menuW, 30)];
        menu.data = emailArr;
        [emailPullMenuView addSubview:menu];
        [menu setValueChangeBlock:^(NSString *text)
         {
             NSLog(@"%@",text);
             menuStr = text;
             
         }];
        menu.layer.borderColor = [UIColor blackColor].CGColor;
        menu.layer.borderWidth = 1;
        NSInteger sendBtnY = 150;
        NSInteger sendBtnH = 30;
        NSInteger sendBtnW = emailPullMenuViewW/3;
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(sendBtnW, sendBtnY, sendBtnW, sendBtnH)];
        [btn setTitle:@"发送" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        btn.backgroundColor = TBColor(237, 237, 237, 1);
        btn.layer.borderColor = TBColor(181, 181, 181, 1).CGColor;
        btn.layer.borderWidth = 1;
        [btn addTarget:self action:@selector(emaiPullsendE) forControlEvents:UIControlEventTouchUpInside];
        [emailPullMenuView addSubview:btn];
        
        UIButton *cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, sendBtnY, sendBtnW, sendBtnH)];
        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [cancelBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        cancelBtn.backgroundColor = TBColor(237, 237, 237, 1);
        cancelBtn.layer.borderColor = TBColor(181, 181, 181, 1).CGColor;

        [cancelBtn addTarget:self action:@selector(emaiPullcancel) forControlEvents:UIControlEventTouchUpInside];
        [emailPullMenuView addSubview:cancelBtn];
        
        //邮箱添加
        UIButton *emailAddBtn = [[UIButton alloc]initWithFrame:CGRectMake(sendBtnW * 2, sendBtnY, sendBtnW, sendBtnH)];
        [emailAddBtn setTitle:@"添加" forState:UIControlStateNormal];
        [emailAddBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [emailAddBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        emailAddBtn.backgroundColor = TBColor(237, 237, 237, 1);
        emailAddBtn.backgroundColor = TBColor(237, 237, 237, 1);
        emailAddBtn.layer.borderColor = TBColor(181, 181, 181, 1).CGColor;

        [emailAddBtn addTarget:self action:@selector(emaiPullAdd) forControlEvents:UIControlEventTouchUpInside];
        [emailPullMenuView addSubview:emailAddBtn];

    }
}
//menu添加
-(void)emaiPullAdd{
    
    UIView *subViews = [self.view viewWithTag:23];
    [subViews removeFromSuperview];
    UIView *emailView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    emailView.tag = 7;
    emailView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:emailView];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(18, SCREENW / 3, SCREENW - 36, 150)];
    view.layer.backgroundColor = TBColor(94, 204, 250, 1).CGColor;
    view.layer.borderWidth = 1;
    view.backgroundColor = [UIColor whiteColor];
    [emailView addSubview:view];
    
    emailLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 5, SCREENW - 105, 30)];
    emailLabel.text = @"请输入邮箱地址:";
    [view addSubview:emailLabel];
    
    emailTextF = [[UITextField alloc]initWithFrame:CGRectMake(25, 40, SCREENW * 4/5, 30)];
    emailTextF.backgroundColor = TBColor(212, 212, 212, 1);
    [view addSubview:emailTextF];
    
    UILabel *textMargin = [[UILabel alloc]initWithFrame:CGRectMake(20, 40, 5, 30)];
    textMargin.backgroundColor = TBColor(212, 212, 212, 1);
    [view addSubview:textMargin];
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(SCREENW * 4/5 - 80, 90, 80, 30)];
    [btn setTitle:@"发送" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    btn.backgroundColor = TBColor(102, 85, 191, 1);
    [btn addTarget:self action:@selector(sendE) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    
    UIButton *cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(40, 90, 80, 30)];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    cancelBtn.backgroundColor = TBColor(102, 85, 191, 1);
    [cancelBtn addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:cancelBtn];
    
}
//menu取消消失
-(void)emaiPullcancel{
    UIView *subViews = [self.view viewWithTag:23];
    [subViews removeFromSuperview];
}
//menu发送
-(void)emaiPullsendE{
    UIApplication *app = [UIApplication sharedApplication];
    NSURL *url = [NSURL URLWithString:menuStr];
    //[app openURL:url];
    UIView *subViews = [self.view viewWithTag:23];
    [subViews removeFromSuperview];
}
//点击取消按钮
-(void)cancel{
    UIView *subViews = [self.view viewWithTag:7];
    [subViews removeFromSuperview];
}
//点击发送邮件按钮
-(void)sendE{
    
    UIApplication *app = [UIApplication sharedApplication];
    NSURL *url = [NSURL URLWithString:emailTextF.text];
    //[app openURL:url];
    [emailTextF addTarget:self action:@selector(sendClick:) forControlEvents:UIControlEventEditingDidEnd];
    UIView *subViews = [self.view viewWithTag:7];
    [subViews removeFromSuperview];
    
}
-(void)sendClick:(UITextField *)textField{
    NSLog(@"添加邮箱");
    [emailArr addObject:textField.text];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
        return info.count;
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 4) {
        NSLog(@"服务记录cell %lu",serveRecordArr.count);
        return serveRecordArr.count+ 1;
        
    }else if (section == 6){
        NSLog(@"配件记录cell %lu",serveRecordArr.count);

        return badPartModArr.count + 1;
    }
    else{
        NSArray *groupInfo = info[section][@"info"];
        return groupInfo.count;

    }
}
#pragma mark 创建每一行的cell
//给cell赋值
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 4) {
        
        ServeRecordCell *cell = [ServeRecordCell ServeRecordCellWithTableView:tableView];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.indexPath = indexPath;
        cell.parentController = self;
        cell.tableV = tableV;
            if (cell.indexPath.row == 0) {
                cell.delBtn.hidden = YES;
            }else{
                cell.delBtn.hidden = NO;
            }
        UITextField *startTimeTF = (UITextField *)[cell viewWithTag:1];
        [startTimeTF addTarget:self action:@selector(beginTimeTFClick) forControlEvents:UIControlEventAllEditingEvents];
        startTimeTF.text =  beginTimeDatePStr;
        UITextField *endTimeTF = (UITextField *)[cell viewWithTag:2];
        endTimeTF.text = endTimeDatePStr;
        [endTimeTF addTarget:self action:@selector(endTimeTFClick) forControlEvents:UIControlEventAllEditingEvents];
        UITextField *trafficTimeTF = (UITextField *)[cell viewWithTag:3];
        trafficTimeTF.text = trafficStr;
        [trafficTimeTF addTarget:self action:@selector(trafficTimeClick:) forControlEvents:UIControlEventEditingDidEnd];
        NSDate *currentDate = [NSDate date];//获取当前时间，日期
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"YYYY-MM-dd"];
        NSString *dateString = [dateFormatter stringFromDate:currentDate];
        NSLog(@"dateString:%@",dateString);
        dic[@"workDate"] = dateString;

        return cell;
    }else if (indexPath.section == 6){
        PartRecordViewCell *cell = [PartRecordViewCell PartRecordCellWithTableView:tableView];
        cell.selectionStyle = UITableViewCellAccessoryNone;
        cell.indexPath = indexPath;
        cell.parentController = self;
        cell.tableV = tableV;
        if (cell.indexPath.row == 0) {
            cell.delBtn.hidden = YES;
        }else{
            cell.delBtn.hidden = NO;
        }
        
        return cell;
        
    }else{

    //根据类创建cell
    NrowLabelViewCell *cell = [NrowLabelViewCell NrowLabelMessageViewWithTableView:tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //根据行号取出模型，赋值
    NSString *str =info[indexPath.section][@"info"][indexPath.row];
    NSLog(@"%@",str);
    cell.infoLabel.text =info[indexPath.section][@"info"][indexPath.row];
//    cell.indexpath
    cell.indexPath = indexPath;
        cell.parentController = self;
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            //客户名称
            UITextField *infoTextField = (UITextField *)[cell viewWithTag:1];
            infoTextField.text = self.strHospitalName;
            
        }else if (indexPath.row == 1){
            //操作人
            UITextField *infoTextField = (UITextField *)[cell viewWithTag:1];
            infoTextField.text = self.strLinkMan;
        }else if (indexPath.row == 2){
            //科室
            UITextField *infoTextField = (UITextField *)[cell viewWithTag:1];
            infoTextField.text = self.strDepartment;
        }else if (indexPath.row == 4){
            //电话
            UITextField *infoTextField = (UITextField *)[cell viewWithTag:1];
            infoTextField.text = self.strMobile;
        }else if (indexPath.row == 5){
            //设备型号
            UITextField *infoTextField = (UITextField *)[cell viewWithTag:1];
            infoTextField.text = self.strTicketNum;
        }
        UITextField *textF = (UITextField *)[cell viewWithTag:1];
        [textF addTarget:self action:@selector(textClick:) forControlEvents:UIControlEventEditingChanged];
        NSLog(@"--------%@",textF.text);
        if ([textF.text isEqualToString:@""]||textF.text == nil) {
            cell.infoLabel.textColor = [UIColor redColor];
            UIView *line = (UIView *)[cell viewWithTag:3];
            line.backgroundColor = [UIColor redColor];
            
        }else{
            cell.infoLabel.textColor = [UIColor blackColor];
            UIView *line = (UIView *)[cell viewWithTag:3];
            line.backgroundColor = TBColor(212, 212, 212, 1);
        }

    }
    if (indexPath.section == 7) {
        if (indexPath.row == 0) {
                UITextField *textF = (UITextField *)[cell viewWithTag:1];
                [textF addTarget:self action:@selector(textClick:) forControlEvents:UIControlEventEditingChanged];
                if ([textF.text isEqualToString:@""]||textF.text == nil) {
                    cell.infoLabel.textColor = [UIColor redColor];
                    UIView *line = (UIView *)[cell viewWithTag:3];
                    line.backgroundColor = [UIColor redColor];
                    
                }else{
                    cell.infoLabel.textColor = [UIColor blackColor];
                    UIView *line = (UIView *)[cell viewWithTag:3];
                    line.backgroundColor = TBColor(212, 212, 212, 1);
                }

            }
    }
    return  cell;
    }
    
}
//celltextField点击事件
-(void)textClick:(UITextField *)textField{
    //获取cell
    UITableViewCell *cell  = (UITableViewCell *)[[textField superview] superview];
    if ([textField.text isEqualToString:@""]||textField.text == nil) {
        
        UILabel *label = (UILabel *)[cell viewWithTag:2];
        label.textColor = [UIColor redColor];
        UIView *line = (UIView *)[cell viewWithTag:3];
        line.backgroundColor = [UIColor redColor];

    }else{
        UILabel *label = (UILabel *)[cell viewWithTag:2];
        label.textColor = [UIColor blackColor];
        UIView *line = (UIView *)[cell viewWithTag:3];
        line.backgroundColor = TBColor(212, 212, 212, 1);
    }
}
//开始时间点击时间
-(void)beginTimeTFClick{
    NSLog(@"开始时间textField点击了");
    UIView *bigView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    bigView.backgroundColor = [UIColor clearColor];
    bigView.tag = 8;
    [self.view addSubview:bigView];
    //datePicker
    dateP = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, SCREENH - 180, SCREENW, 150)];
    dateP.layer.borderColor = TBColor(98, 179, 240, 1).CGColor;
    dateP.layer.borderWidth = 1;
    dateP.backgroundColor = [UIColor whiteColor];
    dateP.layer.masksToBounds = YES;
    dateP.tag = 10;
    dateP.datePickerMode = UIDatePickerModeDateAndTime; // 设置样式
    dateP.date = [NSDate date]; // 设置初始时间
    [dateP addTarget:self action:@selector(benginDatePickerValueChanged:) forControlEvents:UIControlEventValueChanged]; // 添加监听器
    [bigView addSubview:dateP];

    //完成按钮
    UIButton *finishBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, SCREENH - saveBtn.bounds.size.height - 150 + 150, SCREENW, 50)];
    [finishBtn setTitle:@"完成" forState:UIControlStateNormal];
    [finishBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    finishBtn.backgroundColor = [UIColor whiteColor];
    finishBtn.layer.borderColor = TBColor(98, 179, 240, 1).CGColor;
    finishBtn.layer.borderWidth = 1;
    [finishBtn addTarget:self action:@selector(finishBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [bigView addSubview:finishBtn];
}
//结束时间点击textFiedld点击事件
-(void)endTimeTFClick{
    NSLog(@"结束时间textField点击了");
    UIView *bigView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    bigView.backgroundColor = [UIColor clearColor];
    bigView.tag = 8;
    [self.view addSubview:bigView];
    //datePicker
    dateP = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, SCREENH - saveBtn.bounds.size.height - 180, SCREENW, 150)];
    dateP.layer.borderColor = TBColor(98, 179, 240, 1).CGColor;
    dateP.layer.borderWidth = 1;
    dateP.backgroundColor = [UIColor whiteColor];
    dateP.layer.masksToBounds = YES;
    dateP.tag = 10;
    dateP.datePickerMode = UIDatePickerModeDateAndTime; // 设置样式
    dateP.date = [NSDate date]; // 设置初始时间
    [dateP addTarget:self action:@selector(endDatePickerValueChanged:) forControlEvents:UIControlEventValueChanged]; // 添加监听器
    [bigView addSubview:dateP];
    
    //完成按钮
    UIButton *finishBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, SCREENH - saveBtn.bounds.size.height - 150 + 150, SCREENW, 50)];
    [finishBtn setTitle:@"完成" forState:UIControlStateNormal];
    [finishBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    finishBtn.backgroundColor = [UIColor whiteColor];
    finishBtn.layer.borderColor = TBColor(98, 179, 240, 1).CGColor;
    finishBtn.layer.borderWidth = 1;
    [finishBtn addTarget:self action:@selector(finishBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [bigView addSubview:finishBtn];
    

}
//交通时间点击事件
-(void)trafficTimeClick:(UITextField *)textField{
    trafficStr = textField.text;
    dic[@"trafficTime"] = textField.text;
    [tableV reloadData];
}
//完成按钮点击事件
-(void)finishBtnClick{
    UIView *subviews  = [self.view viewWithTag:8];
    [subviews removeFromSuperview];

}
//开始时间datePicker点击事件
-(void)benginDatePickerValueChanged:(UIDatePicker *)sender{
    NSLog(@"获取开始时间");
    NSDate *select = [sender date]; // 获取被选中的时间
    NSDateFormatter *selectDateFormatter = [[NSDateFormatter alloc] init];
    selectDateFormatter.dateFormat = @"yy-MM-dd"; // 设置时间和日期的格式
    NSString *dateAndTime = [selectDateFormatter stringFromDate:select]; // 把date类型转为设置好格式的string类型
    beginTimeDatePStr = dateAndTime;
    dic[@"beginDate"] = beginTimeDatePStr;
    [tableV reloadData];
     NSLog(@"%@",beginTimeDatePStr);
}
//结束时间datePicker点击事件
-(void)endDatePickerValueChanged:(UIDatePicker *)sender{
    NSLog(@"获取结束时间");
    NSDate *select = [sender date]; // 获取被选中的时间
    NSDateFormatter *selectDateFormatter = [[NSDateFormatter alloc] init];
    selectDateFormatter.dateFormat = @"yy-MM-dd"; // 设置时间和日期的格式
    NSString *dateAndTime = [selectDateFormatter stringFromDate:select]; // 把date类型转为设置好格式的string类型
    endTimeDatePStr = dateAndTime;
    dic[@"endDate"] = endTimeDatePStr;
    [tableV reloadData];
    NSLog(@"%@",endTimeDatePStr);

}
//设置cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 4) {
        return 177;
    }else if (indexPath.section == 6){
        return 216;
    }else{
         return 44;
    }
   
    
}
//设置区头
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW , 100)];
    view.backgroundColor = TBColor(235, 235, 235, 1);
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 50)];
    label.font = [UIFont boldSystemFontOfSize:17];
    label.text =[NSString stringWithFormat:@"  %@", info[section][@"header"]];
    
     [view addSubview:label];
    if (section == 1||section == 2|| section == 3||section == 9) {
        //设备类型（单选）
        if (section == 1) {
            UIView *deviceLine = [[UIView alloc]initWithFrame:CGRectMake(0, 50, SCREENW, 1)];
            deviceLine.tag = 12;
            label.tag = 11;
            [view addSubview:deviceLine];
            view.backgroundColor = [UIColor whiteColor];
            deviceArr = [NSArray arrayWithObjects:@"微生物",@"生物分子学",@"免疫",@"工业产品", nil];
            deviceBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREENW * 2/5 + 3, 0, SCREENW - SCREENW/2/5, 50)];
            [deviceBtn setTitle:deviceStr forState:UIControlStateNormal];
            deviceBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            [deviceBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [deviceBtn addTarget:self action:@selector(deviceClick) forControlEvents:UIControlEventTouchUpInside];
            
            [view addSubview:deviceBtn];
            if ([deviceBtn.titleLabel.text isEqualToString:@""]||deviceBtn.titleLabel.text.length == 0) {
                deviceLine.backgroundColor = [UIColor redColor];
                label.textColor = [UIColor redColor];
            }else{
                deviceLine.backgroundColor = TBColor(212, 212, 212, 1);
                label.textColor = [UIColor blackColor];
            }
                self.nLM.eqStyle = deviceBtn.titleLabel.text;
        }
        //服务分类（多选）
        if (section ==2) {
            label.tag = 17;
            view.backgroundColor = [UIColor whiteColor];
            serveBtn = [[UIButton alloc]init];
            [view addSubview:serveBtn];
            serveBtn.frame = CGRectMake(SCREENW /3, 0, SCREENW - SCREENW/3, 50);
            serveBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            serveStr = [[NSMutableString alloc]init];
            serveBtn.titleLabel.font = [UIFont systemFontOfSize:15];
            [serveBtn setTitle:str forState:UIControlStateNormal];
            NSLog(@"打印%@",serveStr);
            [serveBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [serveBtn addTarget:self action:@selector(serveBtnClick) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:serveBtn];
            
            UIView *serveLine = [[UIView alloc]initWithFrame:CGRectMake(0, 50, SCREENW, 1)];
            serveLine.tag = 18;
            serveLine.backgroundColor = TBColor(212, 212, 212, 1);
            [view addSubview:serveLine];
            if ([serveBtn.titleLabel.text isEqualToString:@""]||serveBtn.titleLabel.text.length == 0) {
                serveLine.backgroundColor = [UIColor redColor];
                label.textColor = [UIColor redColor];
            }else{
                serveLine.backgroundColor = TBColor(212, 212, 212, 1);
                label.textColor = [UIColor blackColor];
            }

            
        }
        //保修类型（单选）
        if (section == 3) {
            view.backgroundColor = [UIColor whiteColor];
            maintainArr = [NSArray arrayWithObjects:@"保修期内",@"保修合同",@"收费服务",@"其他", nil];
            maintainBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREENW * 2/5, 0, SCREENW - SCREENW/2/5, 50)];
            maintainBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            [maintainBtn setTitle:maintainStr forState:UIControlStateNormal];
            [maintainBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [maintainBtn addTarget:self action:@selector(mainTainClick) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:maintainBtn];
            
            UIView *maintainLine = [[UIView alloc]initWithFrame:CGRectMake(0, 50, SCREENW, 1)];
            maintainLine.backgroundColor = TBColor(212, 212, 212, 1);
            [view addSubview:maintainLine];
            
            if ([maintainBtn.titleLabel.text isEqualToString:@""]||maintainBtn.titleLabel.text.length == 0) {
                maintainLine.backgroundColor = [UIColor redColor];
                label.textColor = [UIColor redColor];
            }else{
                maintainLine.backgroundColor = TBColor(212, 212, 212, 1);
                label.textColor = [UIColor blackColor];
            }


        }
        //本次服务完成状态（单选）
        if (section == 9) {
            view.backgroundColor = [UIColor whiteColor];

            label.tag = 19;

            //已完成
            MyButton *finishBtn= [MyButton buttonWithType:UIButtonTypeCustom];
            finishBtn.frame = CGRectMake(9, 45, SCREENW * 1/3, 30);
            finishBtn.tag = 20;
            [finishBtn setTitle:@"已完成" forState:UIControlStateNormal];
            [finishBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [finishBtn addTarget:self action:@selector(finishBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            finishBtn.selected = isFinish;
            if (finishBtn.selected ) {
                [finishBtn setImage:[UIImage imageNamed:@"checkbox1_checked"] forState:UIControlStateNormal];
                
                UILabel *label = [self.view viewWithTag:19];
                label.textColor = [UIColor blackColor];
                
            }else{
                [finishBtn setImage:[UIImage imageNamed:@"checkbox1_unchecked"] forState:UIControlStateNormal];
            }
            [view addSubview:finishBtn];
            
            //未完成
            MyButton *unFinishBtn= [MyButton buttonWithType:UIButtonTypeCustom];
            unFinishBtn.frame = CGRectMake(SCREENW/3 + 18, 45, SCREENW * 1/3, 30);
            [unFinishBtn setTitle:@"已完成" forState:UIControlStateNormal];
            unFinishBtn.tag = 21;
            [unFinishBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [unFinishBtn addTarget:self action:@selector(unFinishBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            unFinishBtn.selected = isUnFinish;
            if (unFinishBtn.selected ) {
                [unFinishBtn setImage:[UIImage imageNamed:@"checkbox1_checked"] forState:UIControlStateNormal];
                UILabel *label = [self.view viewWithTag:19];
                label.textColor = [UIColor blackColor];

                
            }else{
                [unFinishBtn setImage:[UIImage imageNamed:@"checkbox1_unchecked"] forState:UIControlStateNormal];
            }
            
             [view addSubview:unFinishBtn];
            
            if (unFinishBtn.selected||finishBtn.selected) {
                label.textColor = [UIColor blackColor];
            }else{
                label.textColor = [UIColor redColor];
            }
        }
    
        return view;

    }
       return view;
    
}
//已完成点击事件
-(void)finishBtnClick:(UIButton *)btn{
    
    UIButton *b = [(UIButton *)self.view viewWithTag:21];
   
    btn.selected = !btn.selected;
    if (btn.selected) {
        [btn setImage:[UIImage imageNamed:@"checkbox1_checked"] forState:UIControlStateNormal];
        UILabel *label = (UILabel *)[self.view viewWithTag:19];
        label.textColor = [UIColor blackColor];
         b.selected = NO;
        
    }else{
        [btn setImage:[UIImage imageNamed:@"checkbox1_unchecked"] forState:UIControlStateNormal];
    }
    isFinish = btn.selected;
    isUnFinish = b.selected;
    [tableV reloadData];
    
}
//未完成点击事件
-(void)unFinishBtnClick:(UIButton *)btn{
    UIButton *b = [(UIButton *)self.view viewWithTag:20];
   

    btn.selected = !btn.selected;
    if (btn.selected) {
        [btn setImage:[UIImage imageNamed:@"checkbox1_checked"] forState:UIControlStateNormal];
        UILabel *label = [self.view viewWithTag:19];
        label.textColor = [UIColor blackColor];
         b.selected = NO;
        
    }else{
        [btn setImage:[UIImage imageNamed:@"checkbox1_unchecked"] forState:UIControlStateNormal];
        }
    isUnFinish = btn.selected;
    isFinish = b.selected;
    [tableV reloadData];
    
}
//设备类型点击事件生成View
-(void)deviceClick{
    NSLog(@"设备点击了");
    UIView *bigView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    bigView.backgroundColor = TBColor(237, 236, 237, .5);
    bigView.tag = 8;
    [self.view addSubview:bigView];
    //字体线变黑
    UILabel *label = (UILabel *)[self.view viewWithTag:11];
    label.textColor = [UIColor blackColor];
    UIView *deviceLine = (UIView *)[self.view viewWithTag:12];
    deviceLine.backgroundColor = TBColor(212, 212, 212, 1);
    
    singleView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, SCREENH - saveBtn.bounds.size.height - 150, SCREENW, 195)];
    singleView.backgroundColor = [UIColor whiteColor];
    singleView.layer.masksToBounds = YES;
    singleView.tag = 1;
    singleView.delegate = self;
    singleView.dataSource = self;
    [bigView addSubview:singleView];
}
//pickerView的count
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}
//pickerView的内容
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (singleView.tag == 1) {
        return deviceArr.count;
    }else if (singleView.tag == 5){
        return satisfiedArr.count;
    }
        return maintainArr.count;
}
#pragma mark pickerView代理方法
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (singleView.tag == 1) {
        return deviceArr[row];
    }else if (singleView.tag == 5){
        return satisfiedArr[row];
    }
        return maintainArr[row];
    
}
// pickerView滚动结束时调用
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (singleView.tag == 1) {
        [deviceBtn setTitle:deviceArr[row]forState:UIControlStateNormal];
        nLM.eqStyle = deviceBtn.titleLabel.text;
        NSLog(@"%@",nLM.eqStyle);
        deviceStr = deviceArr[row];
        UIView *subviews  = [self.view viewWithTag:8];
        [subviews removeFromSuperview];
    }
    if (singleView.tag == 3) {
        [maintainBtn setTitle:maintainArr[row] forState:UIControlStateNormal];
        maintainStr = maintainArr[row];
        nLM.otherType = maintainBtn.titleLabel.text;
        NSLog(@"----%@",nLM.otherType);
        UIView *subviews  = [self.view viewWithTag:8];
        [subviews removeFromSuperview];
    }
    if (singleView.tag == 5) {
        [satisfiedBtn setTitle:satisfiedArr[row] forState:UIControlStateNormal];
        satisfiedStr = satisfiedArr[row];
        UIView *subviews  = [self.view viewWithTag:8];
        [subviews removeFromSuperview];

    }
    [tableV reloadData];
}

//保修类型点击事件生成View
-(void)mainTainClick{
    
    UIView *bigView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    bigView.backgroundColor = [UIColor clearColor];
    bigView.tag = 8;
    [self.view addSubview:bigView];

    singleView = [[UIPickerView alloc]initWithFrame:CGRectMake(10, SCREENH - saveBtn.bounds.size.height - 150, SCREENW - 20, 150)];
    singleView.tag = 3;
    singleView.backgroundColor = [UIColor whiteColor];
    singleView.delegate = self;
    singleView.dataSource = self;
    [bigView addSubview:singleView];
}
//服务分类点击事件
-(void)serveBtnClick{
    
    UIView *bigView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    bigView.backgroundColor = [UIColor clearColor];
    bigView.tag = 9;
    [self.view addSubview:bigView];
    
    //字体线变黑
    UILabel *label = (UILabel *)[self.view viewWithTag:17];
    label.textColor = [UIColor blackColor];
    UIView *deviceLine = (UIView *)[self.view viewWithTag:18];
    deviceLine.backgroundColor = TBColor(212, 212, 212, 1);
    
    doubleView = [[UIView alloc]initWithFrame:CGRectMake(10, 100, SCREENW - 20, 200)];
    doubleView.tag = 1;
    //doubleView.backgroundColor = [UIColor orangeColor];
    doubleView.layer.borderColor = TBColor(107, 198, 252, 1).CGColor;
    doubleView.backgroundColor = [UIColor whiteColor];
    doubleView.layer.borderWidth = 1;
    
    [bigView addSubview:doubleView];
    doubleView.tag = 2;
   
    NSInteger margin = 10;
    NSInteger height = 30;
    
     //第一行的宽
    NSInteger firstWidth = SCREENW / 5;
    NSInteger firstY  = 20;
    
    RSCheckBox *checkBox1=[[RSCheckBox alloc]init];
    NSInteger checkBox1X = 15;
    checkBox1.frame = CGRectMake(checkBox1X, firstY, firstWidth, height);
    checkBox1.backgroundColor = TBColor(212, 212, 212, 1);
    checkBox1.text=@"安装";
    checkBox1.value=1;
    
    NSInteger checkBox2X = checkBox1X + firstWidth + margin;
    RSCheckBox *checkBox2=[[RSCheckBox alloc]initWithFrame:CGRectMake(checkBox2X, firstY, firstWidth, height)];
    checkBox2.backgroundColor = TBColor(212, 212, 212, 1);
    checkBox2.text=@"维修";
    checkBox2.value=2;
    
    NSInteger checkBox3X = checkBox2X + firstWidth + margin;
    RSCheckBox *checkBox3=[[RSCheckBox alloc]initWithFrame:CGRectMake(checkBox3X, firstY, firstWidth, height)];
    checkBox3.backgroundColor = TBColor(212, 212, 212, 1);
    checkBox3.text=@"保养";
    checkBox3.value=3;
    
    NSInteger checkBox4X = checkBox3X + firstWidth + margin;
    RSCheckBox *checkBox4=[[RSCheckBox alloc]initWithFrame:CGRectMake(checkBox4X, firstY, firstWidth, height)];
    checkBox4.backgroundColor = TBColor(212, 212, 212, 1);
    checkBox4.text=@"升级";
    checkBox4.value=4;
    
    //第二行的宽
    NSInteger secondWidth = firstWidth + 20;
    NSInteger secondY = height + margin + firstY;
    NSInteger checkBox5X = checkBox1X;
    
    RSCheckBox *checkBox5=[[RSCheckBox alloc]initWithFrame:CGRectMake(checkBox5X, secondY, secondWidth, height)];
    checkBox5.backgroundColor = TBColor(212, 212, 212, 1);
    checkBox5.text=@"校准/验";
    checkBox5.value=5;
    
    NSInteger checkBox6X = checkBox5X + secondWidth + margin;
    RSCheckBox *checkBox6=[[RSCheckBox alloc]initWithFrame:CGRectMake(checkBox6X, secondY, firstWidth, height)];
    checkBox6.backgroundColor = TBColor(212, 212, 212, 1);
    checkBox6.text=@"移机";
    checkBox6.value=6;
    
    NSInteger checkBox7X = checkBox6X + firstWidth + margin;
    RSCheckBox *checkBox7=[[RSCheckBox alloc]initWithFrame:CGRectMake(checkBox7X, secondY, secondWidth, height)];
    checkBox7.backgroundColor = TBColor(212, 212, 212, 1);
    checkBox7.text=@"其他";
    checkBox7.value=7;
    
    RSCheckBox *checkBox0=[[RSCheckBox alloc]init];
    checkBox0.frame = CGRectMake(checkBox1X,secondY + height +margin * 3 , firstWidth + 10, height);
    checkBox0.backgroundColor = [UIColor redColor];
    checkBox0.text=@"全选";
    checkBox0.textColor = [UIColor whiteColor];
    checkBox0.selectedAll=YES;//设置是否有全选按钮
    
    NSArray *arr=[NSArray arrayWithObjects:checkBox0,checkBox1,checkBox2,checkBox3,checkBox4,checkBox5,checkBox6,checkBox7, nil];
    checkGroup=[[RSCheckGroup alloc]initWithFrame:CGRectMake(0, 0, doubleView.bounds.size.width, doubleView.bounds.size.height) WithCheckBtns:arr];
    checkGroup.isCheck=YES;
    //checkGroup.backgroundColor=[UIColor yellowColor];
    [doubleView addSubview:checkGroup];
    
    NSInteger btnX = checkBox1X + margin + firstWidth + 10;
    UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(btnX,secondY + height +margin * 3 , 100, 30)];
    btn.backgroundColor=[UIColor redColor];
    [btn setTitle:@"确定" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
    [doubleView addSubview:btn];
    
    UIButton *cancelBtn = [[RSCheckBox alloc]initWithFrame:CGRectMake(100 + btnX + margin, secondY + height +margin * 3, firstWidth + 10, height)];
    cancelBtn.backgroundColor = [UIColor redColor];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
    [doubleView addSubview:cancelBtn];

    
    }
-(void)cancelAction{
    NSLog(@"取消");
    UIView *subviews  = [self.view viewWithTag:9];
    [subviews removeFromSuperview];

}
//服务分类多选点击确定按钮事件
-(void)btnAction
{
//    serveStr = nil;
    if (checkGroup.isCheck) {
        for (int i=0; i<checkGroup.selectTextArr.count; i++) {
            
            NSLog(@"%@,%@",checkGroup.selectTextArr[i],checkGroup.selectValueArr[i]);
            [serveStr stringByAppendingString: checkGroup.selectTextArr[i]];
            [serveStr appendString:[NSString stringWithFormat:@",%@",checkGroup.selectTextArr[i]]];
            str = serveStr;
            [serveBtn setTitle:str forState:UIControlStateNormal];
            [serveBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            //NSLog(@"%@",serveStr);
            
        }
    }else{
        NSLog(@"%ld%@",(long)checkGroup.selectValue,checkGroup.selectText);
        NSLog(@"没有复选");
    }
    NSString *str = [serveStr substringFromIndex:1];
    [serveBtn setTitle:str forState:UIControlStateNormal];
    nLM.serviceType = str;
    NSLog(@"%@",nLM.serviceType);
    serveStr = nil;
    serveStr = [NSMutableString new];
    UIView *subviews  = [self.view viewWithTag:9];
    [subviews removeFromSuperview];
    
}
#pragma mark - UITableViewDelegate
//区头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1||section == 3|| section == 2) {
                return 51;
        
    }else if (section == 9){
        return 78;
    }else{
        return 50;
    }
    
}
//设置区尾View
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW,647)];
    footView.backgroundColor = [UIColor whiteColor];
    footView.tag = 4;
    if (section == 0) {
        footView.hidden = YES;
    }
    //设备类型（单选）
    if (section == 1) {
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 45, SCREENW, 1)];
        view.tag = 13;
        view.backgroundColor = TBColor(202, 202, 202, 1);
        [footView addSubview:view];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(9, 0, SCREENW/3, 44)];
        label.tag = 14;
        label.text = @"设备型号*:";
        label.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:label];
        
        UITextField *textF = [[UITextField alloc]initWithFrame:CGRectMake(SCREENW/4, 0, SCREENW - SCREENW / 4, 44)];
        [textF addTarget:self action:@selector(seviceTypeClick:) forControlEvents:UIControlEventEditingChanged];
        [footView addSubview:textF];
        
        if ([textF.text isEqualToString:@""]||textF.text.length == 0) {
            view.backgroundColor = [UIColor redColor];
            label.textColor = [UIColor redColor];
        }else{
            view.backgroundColor = TBColor(212, 212, 212, 1);
            label.textColor = [UIColor blackColor];
        }

        UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(9, 46, SCREENW/4, 44)];
        labelTwo.text = @"序列号*:";
        labelTwo.tag = 15;
        labelTwo.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:labelTwo];

        UITextField *textFTwo =[[UITextField alloc]initWithFrame:CGRectMake(SCREENW/4 + 9, 46, SCREENW - SCREENW /4, 44)];
        textFTwo.text = self.strEqseq;
        [textFTwo addTarget:self action:@selector(seqNumClick:) forControlEvents:UIControlEventEditingChanged];
        [footView addSubview:textFTwo];
        
        UIView *viewTwo = [[UIView alloc]initWithFrame:CGRectMake(0, 91, SCREENW, 1)];
        viewTwo.tag = 16;
        viewTwo.backgroundColor = TBColor(202, 202, 202, 1);
        [footView addSubview:viewTwo];
        
        if ([textFTwo.text isEqualToString:@""]||textFTwo.text.length == 0) {
            viewTwo.backgroundColor = [UIColor redColor];
            labelTwo.textColor = [UIColor redColor];
        }else{
            viewTwo.backgroundColor = TBColor(212, 212, 212, 1);
            labelTwo.textColor = [UIColor blackColor];
        }

    return footView;

    }
    //服务分类（多选）
    if (section == 2) {
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(9, 0, SCREENW/5, 44)];
        label.text = @"其他:";
        label.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:label];
        
        BorderTextField *textF = [[BorderTextField alloc]initWithFrame:CGRectMake(SCREENW /5, 0, SCREENW - SCREENW /5, 44)];
        [textF addTarget:self action:@selector(otherServeTypeType:) forControlEvents:UIControlEventAllEditingEvents];
        [footView addSubview:textF];
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 45, SCREENW, 1)];
        view.backgroundColor = TBColor(202, 202, 202, 1);
        [footView addSubview:view];
        
    }
    //保修类型（单选）
    if (section == 3) {
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(9, 0, SCREENW/5, 44)];
        label.text = @"其他";
        label.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:label];
        
        BorderTextField *textF = [[BorderTextField alloc]initWithFrame:CGRectMake(SCREENW /5, 0, SCREENW - SCREENW /5, 44)];
        [footView addSubview:textF];
        [textF addTarget:self action:@selector(maintainClick:) forControlEvents:UIControlEventAllEditingEvents];
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 45, SCREENW, 1)];
        view.backgroundColor = TBColor(202, 202, 202, 1);
        [footView addSubview:view];

    }
    //故障记录
    if (section == 5) {
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 14, 282, 21)];
        label.text = @"故障现象";
        label.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:label];
        
        UITextView *textV = [[UITextView alloc]initWithFrame:CGRectMake(21, 45, SCREENW - 42, 112)];
        //textV addObserver:self forKeyPath:@selector(failurePhenomenaClick:) options:<#(NSKeyValueObservingOptions)#> context:<#(nullable void *)#>
        textV.layer.backgroundColor = TBColor(212, 212, 212, 1).CGColor;
        textV.backgroundColor = [UIColor whiteColor];
        textV.layer.borderWidth = 1;
        [footView addSubview:textV];
        
        UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(20, 171, 282, 21)];
        labelTwo.text = @"工作内容";
        labelTwo.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:labelTwo];
        
        UITextView *textVTwo = [[UITextView alloc]initWithFrame:CGRectMake(21,202, SCREENW - 42, 112)];
        textVTwo.layer.backgroundColor = TBColor(212, 212, 212, 1).CGColor;
        textVTwo.backgroundColor = [UIColor whiteColor];
        textVTwo.layer.borderWidth = 1;
        [footView addSubview:textVTwo];
    }
    //本次服务完成状态（单选）
    if (section == 9) {

        //下边的线
        UIView *bottomL = [[UIView alloc]initWithFrame:CGRectMake(0, 280, SCREENW , 2)];
        bottomL.backgroundColor = TBColor(202, 202, 202, 1);
        [footView addSubview:bottomL];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20,14, 282,21)];
        label.font = [UIFont boldSystemFontOfSize:17];
        label.text = @"如果未完成，请写明原因:";
        [footView addSubview:label];
        
        UITextView *textFinishV = [[UITextView alloc]initWithFrame:CGRectMake(21, 45, SCREENW - 42, 112)];
        textFinishV.layer.backgroundColor = TBColor(202, 202, 202, 1).CGColor;
        textFinishV.layer.borderWidth = 1;
        textFinishV.backgroundColor = [UIColor whiteColor];
        [footView addSubview:textFinishV];
        
        UITextView *textV = [[UITextView alloc]initWithFrame:CGRectMake(21, 174, SCREENW - 42, 85)];
        textV.text = @"若此次工作报告与上栏列为""已完成"",表示次维修已符合用户要求，仪器已恢复正常工作状态，如用户对此次维修有任何异.，请与三十天内以书面通知我公司";
        textV.userInteractionEnabled = NO;
        textV.font = [UIFont systemFontOfSize:16];
        [footView addSubview:textV];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        btn.frame = CGRectMake(10, 341, SCREENW - 20, 54);
        [btn setTitle:@"请输入签名" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        btn.titleLabel.font = [UIFont systemFontOfSize:17];
        btn.backgroundColor = TBColor(237, 237, 237, 1);
        btn.layer.borderColor = TBColor(181, 181, 182, 1).CGColor;
        btn.layer.borderWidth = 1;
        btn.hidden = NO;
        [btn addTarget:self action:@selector(signClick:) forControlEvents:UIControlEventTouchUpInside];
        [footView addSubview:btn];
        
        signImgView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 337, SCREENW - 20, 150)];
        signImgView.backgroundColor = TBColor(212, 212, 212, 1);
        signImgView.hidden = YES;
        [footView addSubview:signImgView];
        
        //满意度
        UILabel *satisfiedL = [[UILabel alloc]initWithFrame:CGRectMake(10, 287, SCREENW/5, 30)];
        satisfiedL.text = @"满意度:";
        satisfiedL.textColor = [UIColor blackColor];
        [footView addSubview:satisfiedL];
        
        satisfiedArr = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil];
        satisfiedBtn = [[UIButton alloc]initWithFrame:CGRectMake( SCREENW/5, 287, SCREENW - SCREENW /5 - 20 , 30)];
        satisfiedBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [satisfiedBtn setTitle:satisfiedStr forState:UIControlStateNormal];
        [satisfiedBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [satisfiedBtn addTarget:self action:@selector(satisfiedClick) forControlEvents:UIControlEventTouchUpInside];
        [footView addSubview:satisfiedBtn];
        
        UIView *satisfiedLine = [[UIView alloc]initWithFrame:CGRectMake(0, 320, SCREENW, 1)];
        satisfiedLine.backgroundColor = TBColor(212, 212, 212, 1);
        [footView addSubview:satisfiedLine];
        
    }

    return  footView;
}
//保修类型其他（单选）点击事件
-(void)maintainClick:(UITextField *)textField{
    nLM.otherTypeName = textField.text;
}
//服务分类其他（多选）点击事件
-(void)otherServeTypeType:(UITextField *)textField{
    nLM.otherTypeName
    = textField.text;
}
//设备型号点击事件
-(void)seviceTypeClick:(UITextField *)textField{
    
    nLM.eqType = textField.text;
    //设备型号字体线变黑
    if ([textField.text isEqualToString:@""]||textField.text.length == 0) {
        UILabel *label = (UILabel *)[self.view viewWithTag:14];
        label.textColor = [UIColor redColor];
        UIView *Line = (UIView *)[self.view viewWithTag:13];
        Line.backgroundColor = [UIColor redColor];;
    }else{
        UILabel *label = (UILabel *)[self.view viewWithTag:14];
        label.textColor = [UIColor blackColor];
        UIView *Line = (UIView *)[self.view viewWithTag:13];
        Line.backgroundColor = TBColor(212, 212, 212, 1);

    }
}
//序列号点击事件
-(void)seqNumClick:(UITextField *)textField{
    nLM.eqSeq = textField.text;
    //设备型号字体线变黑
    if ([textField.text isEqualToString:@""]||textField.text.length == 0) {
        UILabel *label = (UILabel *)[self.view viewWithTag:15];
        label.textColor = [UIColor redColor];
        UIView *Line = (UIView *)[self.view viewWithTag:16];
        Line.backgroundColor = [UIColor redColor];;
    }else{
        UILabel *label = (UILabel *)[self.view viewWithTag:15];
        label.textColor = [UIColor blackColor];
        UIView *Line = (UIView *)[self.view viewWithTag:16];
        Line.backgroundColor = TBColor(212, 212, 212, 1);
    }

}
//满意度点击事件
-(void)satisfiedClick{
    NSLog(@"满意度点击了");
    UIView *bigView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    bigView.backgroundColor = [UIColor clearColor];
    bigView.tag = 8;
    [self.view addSubview:bigView];
    
    singleView = [[UIPickerView alloc]initWithFrame:CGRectMake(10, SCREENH - saveBtn.bounds.size.height - 150, SCREENW - 20, 150)];
    singleView.backgroundColor = [UIColor whiteColor];
    singleView.layer.masksToBounds = YES;
    singleView.tag = 5;
    singleView.delegate = self;
    singleView.dataSource = self;
    [bigView addSubview:singleView];
}
//点击签名事件
-(void)signClick:(UIButton *)btn{
    NSLog(@"点击了签名");
    SignsViewController *signVC = [[SignsViewController alloc]init];
    [self presentViewController:signVC animated:YES completion:nil];
    
    signVC.isBtn = ^(BOOL isBtn){
        btn.hidden = NO;
        signImgView.hidden = YES;
    };
    
    signVC.block = ^(UIImage *img){
        btn.hidden = YES;
        signImgView.image = img;
        signImgView.hidden = NO;
    };
  }

//设置区尾的高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if ( section == 2 ||section  == 3 ) {
        return 46;
    }else if (section == 1){
          return 92;
    }else if (section == 9){
        return 647;
    }else if (section == 5){
        return 335;
    }else if (section == 7 ){
        return 0;
    }else if (section == 0||section == 8 ||section == 4||section == 6){
        return 1;
    }
    
    return 0;
}
//支持旋转
-(BOOL)shouldAutorotate{
    return YES;
}

//支持的方向 因为界面A我们只需要支持竖屏
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
@end
